export function getToken(){
  wx.request({
    url: `https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=QXRLzp5aSmwXjMII7NMInxKU&client_secret=KGcHRw3O8XndWQXh4VUMYnmbEM3bc4bx`,
    method: "POST",
    success: (res)=>{
      // console.log(res);
      wx.setStorage({
        data: res.data.refresh_token,
        key: "user-token",
      })
    }
  });
}

// 短语音急速识别
export function soundRecoPro(data){
  let token = wx.getStorageSync("user-token");
  if(!token){
    getToken();
  }
  return new Promise((resolve, regest)=>{
    wx.request({
      url: `https://vop.baidu.com/pro_api?dev_pid=80001&cuid=bupt626gaotianxiaochengxu&token=${token}`,
      method: "POST",
      data: data,
      header: {"Content-Type": "audio/pcm;rate=16000"},
      success: (res)=>{
        console.log(res)
        resolve(res.data.result[0]);
      },
      fail: regest
    })
  });
}
// 实时语音识别websocket
export function soundRecoWeb(data){
  let token = wx.getStorageSync("user-token");
  if(!token){
    getToken();
  }
}